package com.jichangxiu.framework.handler;

import com.jichangxiu.common.entity.vo.Result;
import com.jichangxiu.common.enums.ErrorType;
import com.jichangxiu.common.exception.ServiceException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@ResponseBody
@RestControllerAdvice
@RequiredArgsConstructor
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Result<String> error(Exception ex) {
        return Result.no(ErrorType.SERVER_EXCEPTION);
    }

    @ExceptionHandler(RuntimeException.class)
    public Result<String> error(RuntimeException ex) {
        return Result.no(ErrorType.SERVER_EXCEPTION);
    }

    @ExceptionHandler(ServiceException.class)
    public Result<String> error(ServiceException ex) {
        return Result.no(ex);
    }

}

